<?php

class DbConnect {
	protected $host = '' ;
	protected $user = '';
	protected $password = '';
	protected $database = '';
	protected $persistent = false;
	protected $conn;
	protected $error_reporting = false;
	
	function __construct ($host, $user, $password, $database, $error_reporting = true, $persistent = false) {
		$this->host = $host;
		$this->user = $user;
		$this->password = $password;
		$this->database = $database;
		$this->persistent = $persistent;
		$this->error_reporting = $error_reporting;
	}
	
	function open(){
		if ($this->persistent) {
			$this->conn = mysql_pconnect($this->host, $this->user, $this->password);
			if(!$this->conn){
				return (false);
			}
		} else {
			$this->conn = mysql_connect($this->host, $this->user, $this->password);
			if (!$this->conn) {
				return (false);
			}
		}
	
		if (@!mysql_select_db($this->database, $this->conn)) {
			return false;
		}
		return true;
	}
    
	function close() {
		return (@mysql_close($this->conn));
	}
    
	function error() {
		if ($this->error_reporting) {
			return (mysql_error()) ;
		}
	}
}
?>